package com.lwl.office.dcconverter.element;

import cn.hutool.core.util.StrUtil;
import com.lwl.office.dcconverter.style.DCParagraphStyle;
import com.lwl.office.webeditor.ParserContext;
import lombok.Data;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;

@Data
public class DCParagraph extends AbsDCElement {
    public String getTagName(){
        return "p";
    }
    @Override
    public String toHtml() {
        StringBuilder stb = new StringBuilder();
        stb.append("<").append(getTagName()).append(" ");
        if(getStyle()!=null){
            stb.append(getStyle().toHtmlStyle());
        }
        stb.append(">");
        for (AbsDCElement child : getChildren()) {
            stb.append(child.toHtml());
        }
        stb.append("</").append(getTagName()).append(">");
        return stb.toString();
    }

    @Override
    public void parseWord(ParserContext context) {
        XWPFParagraph paragraph;
        if ((!(this.getParent() instanceof DCHeader)) && (!(this.getParent() instanceof DCList))) {
            //正式的段落节点
           paragraph = context.createParagraph();
       }else{
            paragraph = context.getParagraph();
        }
        //渲染段落
        DCParagraphStyle dcps = (DCParagraphStyle) this.getStyle();
        if(dcps!=null){
            dcps.setWordStyle(paragraph);
        }
        //子节点解析成word
        for (AbsDCElement child : getChildren()) {
            child.parseWord(context);
        }
    }
}
